﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BetterJump : MonoBehaviour
{
    public float fallMultiplier = 2.5f;
    public float lowJumpMultipier = 2f;

    private Rigidbody2D  _rigidbody2D;
    // Start is called before the first frame update
    void Start()
    {
        _rigidbody2D = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void FixedUpdate()
    {
        if(_rigidbody2D.velocity.y<0)   // 下落的过程
        {
            _rigidbody2D.gravityScale = fallMultiplier;
        }
        else if(_rigidbody2D.velocity.y>0&&!Input.GetButton("Jump"))    // 一直按着，且是上升中
        {
            _rigidbody2D.gravityScale = lowJumpMultipier;
        }
        else
        {
            _rigidbody2D.gravityScale = 1f;
        }
    }
}
